<!--清算账户自动拆借管理申请录入页面-->
<template>
  <div class="app-container">
    <ht-search-form
      v-show="showSearch"
      :dictMap="dictMap"
      :queryParams="queryParams"
      :outputQueryParams="queryParams"
      :formOptions="formOptions"
      :advOptions="[]"
      defaultEventKey="entryTable"
    ></ht-search-form>
    <ht-table
      ref="dataTable"
      :showSerialNumber="false"
      :multi-select="false"
      :dictMap="dictMap"
      :reqConfig="reqConfig"
      :queryParams="queryParams"
      :tableBindColumns="tableBindColumns"
      :opButtonList="opButtonList"
      defaultEventKey="entryTable"
    >
      <template v-slot:operate>
        <el-table-column label="操作" align="center" width="120" fixed="right" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '撤销',
                  // permission: 'user:xxx:xxx',
                  visible: scope.row.status !== '01',
                  doFunc: () => {
                    handleAction('revocation', scope.row);
                  },
                },
                {
                  label: '恢复额度',
                  // permission: 'user:xxx:xxx',
                  visible: scope.row.status !== '01',
                  doFunc: () => {
                    handleAction('recoveryQuota', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>
    <!-- 签约操作弹出框 -->
    <sign-agreement
      ref="signAgreementDialog"
      :dictMap="dictMap"
      :formData="formData"
      @editComplete="editComplete"
    ></sign-agreement>
    <!-- 恢复额度操作弹出框 -->
    <recovery-quota
      ref="recoveryQuotaDialog"
      :dictMap="dictMap"
      :formData="formData"
      @editComplete="editComplete"
    ></recovery-quota>
  </div>
</template>
<script>
import { apiUrlConfig, quota, cancleUrl } from "@/api/cnaps/saps/clearAcctAutoMng/clear_manage_apply_entry.js";
import { listPageMixin } from "@/libs/listPageMixin";
import { log } from "util";
import { amountThousandsFormatter } from "@/utils/table_col_formatter";
import SignAgreement from "./components/signAgreement";
import RecoveryQuota from "./components/recoveryQuota";
import { mapGetters } from "vuex";

export default {
  name: "clearManageApplyEntry",
  mixins: [listPageMixin],
  components: { SignAgreement, RecoveryQuota },
  data() {
    return {
      reqConfig: apiUrlConfig,
      total: 0,
      dataList: [],
      //数据字典
      searchFormDictList: ["AGREE_STATUS", "PROCESSSTATUS"],
      //  明细弹框数据
      // form表单字段
      formData: {
        protoNum: "",
        cStBrno: "",
        cStBrnoName: "",
        dStBrno: "",
        dStBrnoName: "",
        lowerCurcd: "",
        amtLowerLmt: "",
        upperCurcd: "",
        amtUpperLmt: "",
        remarks: "",
      },
      showSearch: true,
      // 查询参数
      queryParams: {
        prono: "",
        status: "",
      },
      formOptions: [],
      opButtonList: () => {
        return [
          {
            label: "签约",
            type: "primary",
            icon: "",
            // permission: "user:xxx:xxx",
            clickFun: () => {
              this.handleAction("signContract");
            },
          },
        ];
      },
      tableBindColumns: [
        { label: `协议号`, prop: "prono", sortable: false },
        { label: `拆入清算行`, prop: "cStBrno", sortable: false },
        { label: `拆出清算行`, prop: "dStBrno", sortable: false },
        {
          prop: "amtLowerLmt",
          label: "拆借金额下限",
          type: "price",
        },
        {
          prop: "amtUpperLmt",
          label: "拆借金额上限",
          type: "price",
        },
        {
          label: `协议状态`,
          prop: "status",
          dictCode: "AGREE_STATUS",
          sortable: false,
        },
        {
          label: `状态变更时间`,
          prop: "stChangetime",
          sortable: false,
          type: "date",
        },
      ],
    };
  },
  mounted() {
    this.formOptions = [
      {
        type: "input",
        prop: "prono",
        defaultAttr: {
          label: "协议号",
          placeholder: "请输入协议号",
        },
      },
      {
        type: "dict",
        dict: "AGREE_STATUS",
        prop: "status",
        defaultAttr: {
          label: "协议状态",
          placeholder: "请选择协议状态",
        },
      },
    ];
  },
  computed: {
    ...mapGetters(["globalBusData"]),
  },
  watch: {
    globalBusData: {
      handler(val) {
        this.$set(this.formData, "cStBrno", val.cnapsBrno);
        this.$set(this.formData, "cStBrnoName", val.cnapsBrname);
        this.$nextTick(() => {
          this.$refs.dataTable.doQuery();
        });
      },
      deep: true,
      immediate: true,
    },
  },
  methods: {
    editComplete(state) {
      if (state == true) {
        this.$refs.dataTable.doQuery();
      }
    },
    handleAction(type, row = {}) {
      switch (type) {
        case "signContract":
          // 签约
          this.$set(this.formData, "lowerCurcd", "CNY");
          this.$set(this.formData, "upperCurcd", "CNY");
          this.$refs.signAgreementDialog.show();
          break;
        case "revocation":
          // 撤销
          this.$confirm("确认要撤销此协议吗?", "系统提示", {
            confirmButtonText: "确认",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(function () {
              return cancleUrl(row);
            })
            .then(() => {
              this.$refs.dataTable.doQuery();
              this.msgSuccess("撤销成功！");
            })
            .catch((action) => {});
          break;
        case "recoveryQuota":
          // 恢复额度
          quota({ prono: row.prono, cStBrno: row.cStBrno, dStBrno: row.dStBrno }).then((res) => {
            this.formData = _.clone(res.result);
            this.$refs.recoveryQuotaDialog.show();
          });

          break;
      }
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}
</style>
